
<template>
  <el-dialog :close-on-click-modal="false" :title="$tt('label_tms_appointment_send')" :visible.sync="visible" custom-class="dialog_auto"
    v-loading="loading">

    <el-form :label-width="$globalCss.formLabelWidth_default" :model="form" :rules="rules" ref="Form">


      <el-form-item :label="$tt('label_tms_appointment_time')" prop="reservationTime">
        <ex_super_input v-model="form.reservationTime" class="form_input_small" type="date-picker" :attrs="{
          type:'datetime',
          'picker-options': {
            disabledDate: t => {
              return t.getTime() < new Date().getTime()
            }
          }
        }" />
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog_footer">
      <el-button @click="visible = false">{{ $tt('label_cancel') }}</el-button>
      <el-button type="primary" @click="submitReady">{{ $tt('label_submit') }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  components: {},
  data() {
    return {

      visible: false,
      loading: false,
      form: {
        reservationTime: null
      },

      itemList: [],
      rules: {
        reservationTime: {
          required: true, validator: (r, v, cb) => {
            if (v < new Date().getTime()) {
              cb(this.$tt('label_tms_not_lt_current_time'))
            } else {
              cb()
            }
          }, trigger: 'blur'
        },
      },
    }
  },
  computed: {



  },
  methods: {


    show(item,) {
      this.visible = true
      this.itemList = Object.assign(_.cloneDeep(item))

      this.form = { reservationTime: new Date().getTime() }
    },

    submitReady() {
      this.$refs['Form'].validate((valid) => {
        if (valid) {
          this.submit()
        } else {
          this.$message.error(this.$tt('form_validate_error'))
          return false;
        }
      });
    },
    hide() {
      this.visible = false
    },
    submit() {

      this.$ajax({
        url: "/tms-api/waybill/TmsTaskInfoOperationRpc/reservationIssued.json",
        method: 'post', type: 'json',
        loading: true,
        data: {
          reservationTime: this.form.reservationTime,
          waybillIdAndVersionList: this.itemList.map(it => {
            return {
              id: it.id,
              version: it.version,
            }
          }),
        },
        success: (res) => {
          this.$message.success(this.$tt('tip_submit_success'))
          this.hide()
          this.$emit('submitSuccess')
        },
      })


    },

  }
}
</script>
